# Maintainer: Johannes Schindelin <johannes.schindelin@gmx.de>

_realname=xpdf
pkgbase="mingw-w64-${_realname}-tools"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}-tools")
#conflicts=("${MINGW_PACKAGE_PREFIX}-poppler")
pkgver=4.00
pkgrel=1
pkgdesc="Utilities for PDF files (mingw-w64)"
arch=('any')
license=('GPL2+')
url="http://foolabs.com/xpdf/"
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-zlib")
options=('strip')
source=(https://xpdfreader-dl.s3.amazonaws.com/xpdf-${pkgver}.tar.gz{,.sig}
        001-cmake.patch
        002-xpdf-4.00-64bit.patch
        003-xpdf-4.00-libpaperfix.patch
        004-xpdf-4.00-man-path-fix.patch
        005-xpdf-4.00-permissions.patch
        006-xpdf-4.00-only-tools.patch)
sha256sums=('ff3d92c42166e35b1ba6aec9b5f0adffb5fc05a3eb95dc49505b6e344e4216d6'
            'SKIP'
            'df71b83964dfb7ae1c5ce2d37c6634bbda27288609e7a5248e2142f0ddbec2c0'
            '80e2f2de83904db8916972c6afd49b2868879517eb99ec8ee44ca06c158629d7'
            '4a6f8a7c4d7dd8dc45a5af7fbe305d41c95714618bf2c2ba5a396f492657c61a'
            '0e08bba11047b5e2e38866cf4b876d674a300b928b6603f27a3ffa124104fb24'
            '22e0afda66f036cea8643252762e1391ed078102dd5f76f8cf862976b4b37089'
            '90b9393d65997d075e6044f8156404f0fdc03444ee2f2208cfabd0fe94ecf267')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-cmake.patch
  patch -p1 -i ${srcdir}/002-xpdf-4.00-64bit.patch
  patch -p1 -i ${srcdir}/003-xpdf-4.00-libpaperfix.patch
  patch -p1 -i ${srcdir}/004-xpdf-4.00-man-path-fix.patch
  patch -p1 -i ${srcdir}/005-xpdf-4.00-permissions.patch
  patch -p1 -i ${srcdir}/006-xpdf-4.00-only-tools.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DMULTITHREADED=ON \
    -DCMAKE_BUILD_TYPE=Release \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install

  cd ${srcdir}/${_realname}-${pkgver}
  install -Dm 644 xpdf-qt/xpdf-icon.svg "${pkgdir}${MINGW_PREFIX}/share/pixmaps/xpdf.svg"
  install -Dm 644 README CHANGES -t "${pkgdir}${MINGW_PREFIX}/share/doc/${pkgname}"

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING3 ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING3
}
